package com.life.smile.controller.equipmentRecord;

import java.util.List;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;

import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
import com.life.smile.entity.EquipmentRecord;
import com.life.smile.msg.ApiResultModel;
import net.sf.json.JSONArray;
import com.life.smile.utils.HttpUtil;
import com.life.smile.utils.Base64Util;
@Controller
@RequestMapping("jsp/equipment")
public class EquipmentRecordController {
	
	/**
	 * 查询司机和乘客用户登录记录日记信息
	 * @param request
	 * @param response
	 * @return EquipmentRecord的list集合   || 页面路径
	 * 
	 */
	@SuppressWarnings("unchecked")
	@RequestMapping(value = "getEquipmentRecordInfo", method = RequestMethod.GET)
	public String getEquipmentRecordInfo(HttpServletRequest request, HttpServletResponse response) {
		String url = "/api/smile/getUser";
		Gson gson = new GsonBuilder().serializeNulls().create();
		String str = HttpUtil.httpURLConectionGET(url);
		String base = Base64Util.decode(str);
		ApiResultModel jsonObject = gson.fromJson(base, ApiResultModel.class);// 把JSON字符串转为对象
		JSONArray jsonArray = JSONArray.fromObject(jsonObject.getData());
		// Java集合
		List<EquipmentRecord> drivers = (List<EquipmentRecord>) JSONArray.toCollection(jsonArray, EquipmentRecord.class);
//		for (EquipmentRecord driverUserVo : drivers) {
//			if (driverUserVo.getCreateDate() != null) {
//				driverUserVo.setStringcreateDate(DateUtils.formatDateTime(driverUserVo.getCreateDate()));
//			}
//		}
		request.setAttribute("drivers", drivers);
		return "driver/driverList";
	}

}
